/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */

/**
 * Encodes a tree to a single string.
 *
 * @param {TreeNode} root
 * @return {string}
 */
var serialize = function(root) {
    return rserialize(root, '');
};

/**
 * Decodes your encoded data to tree.
 *
 * @param {string} data
 * @return {TreeNode}
 */
var deserialize = function(data) {
    const dataList = data.split(','); //必须要加分割符
    return rdeserialize(dataList)
};
var rserialize = (root, str) => {
  if(root == null) {
    str += 'None,';
  }else {
    str += root.val + ',';
    str = rserialize(root.left, str);
    str = rserialize(root.right, str);
  }
  return str
}
var rdeserialize = (dataList) => {
  if(dataList[0] === 'None') {
    dataList.shift();
    return null;
  }
  const root = new TreeNode(parseInt(dataList[0]));
  dataList.shift();
  root.left = rdeserialize(dataList);
  root.right =rdeserialize(dataList);
  return root;
}

/**
 * Your functions will be called as such:
 * deserialize(serialize(root));
 */